package com.gitee.feizns.web.domain.page;

import com.baomidou.mybatisplus.plugins.Page;
import com.gitee.feizns.convert.ConvertUtils;
import org.apache.ibatis.session.RowBounds;

/**
 * @author feizns
 * @since 2019/7/8
 */
public class RowBoundsPageVo implements PageVo {

    private PageAo pageAo;

    private RowBounds rowBounds;

    public RowBoundsPageVo(PageAo pageAo) {
        this.pageAo = pageAo;
        this.rowBounds = pageAo.toRowBounds();
    }

    @Override
    public Long getOffset() {
        if ( rowBounds instanceof Page)
            return null;
        return ConvertUtils.to(pageAo.getOffset(), Long.class, 0L);
    }

    @Override
    public Long getLimit() {
        if ( rowBounds instanceof Page )
            return null;
        return ConvertUtils.to(pageAo.getLimit(), Long.class);
    }

    @Override
    public Long getSize() {
        if ( rowBounds instanceof Page )
            return Long.valueOf(((Page) rowBounds).getSize());
        return null;
    }

    @Override
    public Long getPages() {
        if ( rowBounds instanceof Page )
            return ((Page) rowBounds).getPages();
        return null;
    }

    @Override
    public Long getCurrent() {
        if ( rowBounds instanceof Page )
            return ConvertUtils.to(((Page) rowBounds).getCurrent(), Long.class);
        return null;
    }

    @Override
    public Long getTotal() {
        if ( rowBounds instanceof Page )
            return ((Page) rowBounds).getTotal();
        if ( rowBounds instanceof TotalRowBounds )
            return ((TotalRowBounds) rowBounds).getTotal();
        return null;
    }

}
